﻿using System;
using System.Collections.Generic;

using IDAL.AuthModel;
using Model.AuthModel;
using Model.Base;
using DALFactory.AuthModel;
namespace BLL.AuthModel
{
    /// <summary>
    /// 通用组件，权限模型，业务层，角色
    /// </summary>
    public class RolesBLL
    {
        IRoles dal = DataAccess.CreateRole();

        /// <summary>
        /// 新增角色
        /// </summary>
        /// <param name="rolesName"></param>
        /// <param name="rolesDescription"></param>
        /// <param name="message"></param>
        /// <returns></returns>
        public int InsertRoles(string rolesName, string rolesDescription, out string message)
        {
            RolesInfo info = new RolesInfo();
            info.RolesName = rolesName;
            info.RolesDescription = rolesDescription;
            return dal.InsertRoles(info, out message);
        }

        /// <summary>
        /// 修改角色
        /// </summary>
        /// <param name="rolesID"></param>
        /// <param name="rolesName"></param>
        /// <param name="rolesDescription"></param>
        /// <param name="message"></param>
        /// <returns></returns>
        public bool UpdateRoles(int rolesID, string rolesName, string rolesDescription, out string message)
        {
            RolesInfo info = new RolesInfo();
            info.RolesID = rolesID;
            info.RolesName = rolesName;
            info.RolesDescription = rolesDescription;
            return dal.UpdateRoles(info, out message);
        }

        /// <summary>
        /// 根据编号获取role
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public RolesInfo GetRolesByID(int id) 
        {
            return dal.GetRolesByID(id);
        }

        /// <summary>
        /// 角色列表
        /// </summary>
        /// <returns></returns>
        public IList<RolesInfo> ListRoles() 
        {
            
            BaseCondition condition = new BaseCondition();
            condition.OrderBy = "RolesID ASC";
            return dal.ListRoles(condition);
        }

        /// <summary>
        /// 获取角色拥有的权限
        /// </summary>
        /// <param name="rolesID"></param>
        /// <returns></returns>
        public IList<RolesInfo> ListAuthByRoles(int rolesID)
        {

            RolesCondition condition = new RolesCondition();
            condition.RolesID = rolesID;
            condition.OrderBy = "RolesID ASC";
            return dal.ListRolesAuth(condition);
        }
    }
}
